
R3F_FNCT_Para = {
	private "_return";
	_return = false;
	if (count _this > 2) then {
		private ["_side","_item","_pos","_poslz","_postart","_nbr","_vehicle","_dir","_pilote","_group","_alt","_dist","_space","_speed","_grp_task","_array"];
		_side = _this select 0;
		if (typeName _side != "SIDE") exitWith {};
		_item = _this select 1;
		if (isNil "_item") exitWith {};
		_pos = [_item] call R3F_FNCT_GetPos;
		if (count _pos == 0) exitWith {};
		_postart = [_pos select 0,_pos select 1,100];
		_item = _this select 2;
		if (isNil "_item") exitWith {};
		_poslz = [_item] call R3F_FNCT_GetPos;
		if (count _pos == 0) exitWith {};
		if (count _this > 3) then {
			_nbr = _this select 3;
			if (_side == east && _nbr > 15) then {
				_nbr = 15;
			};
			if (_side == west && _nbr > 26) then {
				_nbr = 26;
			};
		} else {
			_nbr = 10;
		};
		if (count _this > 4) then {
			_grp_task = _this select 4;
		} else {
			_grp_task = "HOLD";
		};
		_dir = [_postart,_poslz] call BIS_fnc_dirTo;
		if (_side == west) then {
			_vehicle = "C130J_US_EP1";
		} else {
			_vehicle = "AN2_TK_EP1";
		};
		_array = [_postart,_dir,_vehicle,_side] call BIS_fnc_spawnVehicle;
		_vehicle = _array select 0;
		_pilote = driver _vehicle;
		_vehicle flyInHeight 300;
		_pilote move _poslz;
		_group = [_side,_postart,_nbr] call R3F_FNCT_Creat_Group;
		{_x moveincargo _vehicle;} foreach units _group;
		waitUntil {((_pilote distance _poslz) < 2000) || (getDammage _vehicle > 0.8) || !(canMove _vehicle) || !(alive _pilote)};
		if (_side == west) then {
			_alt = 100;
			_space = 25;
			_speed = "LIMITED";
		} else {
			_alt = 75;
			_space = 35;
			_speed = "NORMAL";
		};
		group _pilote setSpeedMode _speed;
		_dist = (_nbr * _space) + _alt;
		_vehicle flyInHeight _alt;
		waitUntil {((_pilote distance _poslz) < _dist) || (getDammage _vehicle > 0.8) || !(canMove _vehicle) || !(alive _pilote)};
		[_group,_vehicle,"EJECT"] call R3F_FNCT_GroupOut;
		[_group,_grp_task,_poslz] call R3F_FNCT_GrpAssignTask;
		[_pilote] call R3F_FNCT_Vehicle_Delete;
		_return = true;
	};
	_return;
};
R3F_FNCT_GrpAssignTask = {
	private "_return";
	_return = false;
	if (count _this == 3) then {
		private ["_group","_grp_task","_wp","_pos"];
		_group = _this select 0;
		_grp_task = _this select 1;
		_pos = _this select 2;
		_group setBehaviour "AWARE";
		_group setCombatMode "RED";
		_group setFormation "VEE";
		switch (toUpper _grp_task) do {
			waitUntil {((getPosATL leader _group) select 2) < 1};
			case "PATROL" : {
				sleep 120;
				if !(isNil "R3F_FNCT_Patrol") then {
					[_group,200] spawn R3F_FNCT_Patrol;
				} else {
					[_group,_pos,200] call BIS_fnc_TaskPatrol;
				};
			};
			case "DEFEND" : {
				[_group,_pos] call BIS_fnc_TaskDefend;
			};
			default {
				_wp = _group addWaypoint [_pos,50];
				_wp setWaypointType _grp_task;
			};
		};
		_return = true;
	};
	_return;
};
R3F_FNCT_Creat_Group = {
	private "_group";
	_group = false;
	if (count _this > 1) then {
		private ["_side","_pos","_grp_def","_nbr","_skill","_init","_class","_rank","_units","_worldname","_desert"];
		_side = _this select 0;
		if (typeName _side != "SIDE") exitWith {};
		_pos = _this select 1;
		if (typeName _pos != "ARRAY") exitWith {};
		_nbr = _this select 2;
		_worldname = toLower worldName;
		if ((_worldName == "takistan") || (_worldName == "zargabad") || (_worldName == "fallujah")) then {_desert = true;} else {_desert = false;};
		_grp_def = [[7,"LIEUTENANT"],[1,"SERGEANT"],[0,"SERGEANT"],[3,"CORPORAL"],[2,"CORPORAL"],[0,"CORPORAL"],[1,"CORPORAL"],[4,"PRIVATE"],[5,"PRIVATE"],[1,"PRIVATE"],[6,"PRIVATE"]];
		// maximum d'embarquement d'un MI17 ou AN-2 : 15, d'un C130 : 26
		if (_nbr < count _grp_def) then {
			_nbr = count _grp_def;
		};
		if (count _this > 3) then {
			_skill = _this select 3;
		} else {
			_skill = 0.8;
		};
		if (count _this > 4) then {
			_init = _this select 3;
		} else {
			_init = "";
		};
		//_rank = ["PRIVATE","CORPORAL","SERGEANT","LIEUTENANT","CAPTAIN","MAJOR","COLONEL"];
		if (count _this > 5) then {
			_rank = _this select 4;
		} else {
			_rank = "PRIVATE";
		};
		if (_side == west) then {
			if (_desert) then {
				_class = ["US_Soldier_EP1","US_Soldier_GL_EP1","US_Soldier_MG_EP1","US_Soldier_LAT_EP1","US_Soldier_AA_EP1","US_Soldier_AT_EP1","US_Soldier_Marksman_EP1","US_Soldier_Officer_EP1"];
			} else {
				_class = ["USMC_Soldier","USMC_Soldier_GL","USMC_Soldier_MG","USMC_Soldier_LAT","USMC_Soldier_AA","USMC_Soldier_AT","USMC_SoldierM_Marksman","USMC_Soldier_Officer"];
			};
		} else {
			if (_desert) then {
				_class = ["TK_Soldier_EP1","TK_Soldier_GL_EP1","TK_Soldier_MG_EP1","TK_Soldier_LAT_EP1","TK_Soldier_AA_EP1","TK_Soldier_AT_EP1","TK_Soldier_Sniper_EP1","TK_Soldier_Officer_EP1"];
			} else {
				_class = ["RU_Soldier","RU_Soldier_GL","RU_Soldier_MG","RU_Soldier_LAT","RU_Soldier_AA","RU_Soldier_AT","RU_Soldier_Marksman","RU_Soldier_Officer"];
			};
		};
		_group = createGroup _side;
		for "_i" from 0 to ((count _grp_def) - 1) do {
			(_class select ((_grp_def select _i) select 0)) createUnit [_pos,_group,_init,_skill,(_grp_def select _i) select 1];
			sleep 0.01;
		};
		if (_nbr > count _grp_def) then {
			_nbr = _nbr - (count _grp_def);
			for [{_x = 0},{_x < _nbr},{_x = _x + 1}] do {
				(_class select 0) createUnit [_pos,_group,_init,_skill,_rank];
				sleep 0.01;
			};
		};
	};
	_group;
};
R3F_FNCT_GroupOut = {
	private "_return";
	_return = false;
	if (count _this == 3) then {
		private ["_group","_vehicle","_action","_i","_units"];
		_group = _this select 0;
		_vehicle = _this select 1;
		_action = _this select 2;
		_units = units _group;
		for "_i" from ((count _units) - 1) to 0 step - 1 do {
			((_units) select _i) action [_action,_vehicle];
			unassignvehicle ((_units) select _i);
			sleep 0.4;
		};
		_return = true;
	};
	_return;
};
R3F_FNCT_Vehicle_Delete = {
	private "_return";
	_return = false;
	if (count _this == 1) then {
		private ["_pilote","_vehicle","_pos","_group"];
		_pilote = _this select 0;
		_group = group _pilote;
		_vehicle = vehicle _pilote;
		waitUntil {((count assignedCargo _vehicle) < 1) || (getDammage _vehicle > 0.8) || !(canMove _vehicle) || !(alive _pilote)};
		_pos = position _vehicle;
		sleep 5;
		_group setSpeedMode "FULL";
		_pilote move [0,0];
		waitUntil {((_pilote distance _pos) > 1000) || (getDammage _vehicle == 1) || !(canMove _vehicle) || !(alive _pilote)};
		_vehicle flyInHeight 800;
		waitUntil {((_pilote distance [0,0]) < 1000) || (getDammage _vehicle == 1) || !(canMove _vehicle) || !(alive _pilote)};
		sleep 60;
		deletevehicle _pilote;
		deletevehicle _vehicle;
		sleep 1;
		deleteGroup _group;
		_return = true;
	};
	_return;
};
